package com.lhg;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class TestInetAddress {
    public static void main(String[] args) throws Exception {
        InetAddress inetAddress = null;
        InetAddress localHost = null;
            // 在给定主机名的情况下确定主机的 IP 地址。
        try {
            inetAddress = InetAddress.getByName("www.baidu.com");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        localHost = InetAddress.getLocalHost();
        System.out.println("localHost.getHostName() = " + localHost.getHostName());
        System.out.println("localHost.getHostAddress() = " + localHost.getHostAddress());

        System.out.println(inetAddress.getHostAddress());
        System.out.println("localHost = " + localHost);
    }
}
